from django.db import models

# Create your models here.
from django.db import models
from utils.BaseModel import BaseModel


class CategoryModel(BaseModel):
    name = models.CharField(max_length=32, verbose_name="课程分类名称")
    parent = models.ForeignKey("self", null=True, on_delete=models.CASCADE, verbose_name="父级分类", related_name='son')
    recommend = models.BooleanField(default=False, verbose_name="是否推荐")
    ishot = models.BooleanField(default=False, verbose_name="是否热门")
    isgood = models.BooleanField(default=False, verbose_name="是否精品")

    class Meta:
        db_table = "fgcategory"

    def __str__(self):
        return self.name


#老师模型
class TeacherModel(BaseModel):
    name = models.CharField(max_length=32, verbose_name="老师名称")
    image = models.ImageField(upload_to="teacher", verbose_name="老师头像")
    jobtitle = models.CharField(max_length=32, verbose_name="老师职称")
    intro = models.TextField(verbose_name="老师简介")
    sales = models.IntegerField(default=0, verbose_name="销量")

    class Meta:
        db_table = "fgteacher"

    def __str__(self):
        return self.name

#课程模型
class CourseModel(BaseModel):
    name = models.CharField(max_length=32, verbose_name="课程名称")
    image = models.ImageField(upload_to="course", verbose_name="课程图片")
    price = models.DecimalField(max_digits=10, decimal_places=2, verbose_name="课程价格")
    category = models.ForeignKey(to="CategoryModel", on_delete=models.CASCADE, verbose_name="课程分类")
    teacher = models.ForeignKey(to="TeacherModel", on_delete=models.CASCADE, verbose_name="授课老师")
    intro = models.TextField(verbose_name="课程简介")
    level = models.CharField(max_length=32, choices=((0,'初级'),(1,'中级'),(2,'高级')),default=0, verbose_name="课程难度")
    numbers = models.IntegerField( verbose_name="课程人数")
    is_home = models.BooleanField(default=True, verbose_name="是否推荐")
    video = models.CharField(max_length=200, verbose_name="视频路径",default="http://127.0.0.1:8000/uploads/course/video/1.mp4")
    class Meta:
        db_table = "fgcourse"

    def __str__(self):
        return self.name
